﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>普通页面</title>
    <!-- Bootstrap -->
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="/CSS/Base/BaseClass.css?cssver=4" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none; /*元素不能被选中*/
        }

        .lev1 {
            /*//  margin-left: 10px;*/
        }

        .lev2 {
            padding-left: 40px;
        }

        .list-group .lev2:first-child {
            padding-left: 40px;
            border-top: 1px solid #ddd !important;
        }

        .peples .list-group-item {
            padding-bottom: 5px;
            padding-top: 5px;
        }

        .media-left {
            padding-right: 5px;
        }

        .media-body {
            padding-top: 5px;
        }

        .media-heading {
            margin-top: 8px;
        }

        .list-group-item:hover {
            background-color: #3085DB;
        }


        .isel {
            position: absolute;
            top: 18px;
            right: 10px;
            color: darkgoldenrod;
            font-size: 18px;
        }

        .pCard {
            min-width: 80px;
            text-align: center;
            margin: 8px 3px;
        }

            .pCard:hover .badge {
                visibility: visible;
            }

        .panel-body .badge {
            position: absolute;
            top: -5px;
            right: -6px;
            background-color: red;
            padding-left: 5px;
            padding-right: 5px;
            visibility: collapse;
        }
    </style>
</head>
<body ms-controller="RoleSelect">
    <div class="container-fluid" style="margin:10px" id="dvContent">  
            <table class="table table-bordered table-hover table-striped" id="khgl">
                <thead>
                    <tr>
                        <th class="text-center"><i class="fa fa-square-o" ms-click="SelRoleAll(this)"></i></th>
                        <th class="text-center">角色名称</th>
                        <th class="text-center">角色描述</th> 
                    </tr>
                </thead>
                <tbody>
                    <tr ms-repeat-role="QueryRoles">
                        <td class="text-center"><i class="fa " ms-class-2="fa-square-o:!role.issel" ms-class-1="fa-check-square-o:role.issel" ms-click="SelRole(role,this)"></i></td>
                        <td>{{role.RoleName}}</td>
                        <td>{{role.RoleDec}}</td> 
                    </tr>
                </tbody>
            </table> 
    </div>
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <script>
        var model = avalon.define({
            $id: "RoleSelect",
            isSignle: ComFunJS.getQueryString("issignle") ? ComFunJS.getQueryString("issignle") : "N",
            checkval: ComFunJS.getQueryString("checkvalue") ? ComFunJS.getQueryString("checkvalue") : "",
            selBM: {},//已选择部门
            GetRoleList: function (el) { 
                $.getJSON('/API/SZHLAPI.ashx?Action=GETROLE', function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        resultData.Result.forEach(function (el) {
                            if (ComFunJS.FindItem(model.SelRoles, function (e) {
                     return e.RoleCode == el.RoleCode;
                            }).length == 0) {
                                el.issel = false
                            } else {
                                el.issel = true
                            } 
                        })
                        model.QueryRoles = resultData.Result;
                    }
                })
            },

            SelRole: function (item, dom) {
                if (model.isSignle == "Y") {
                    model.SelRoles.clear();
                    model.QueryRoles.forEach(function (role) {
                        role.issel = false;
                    })

                }
                item.issel = !item.issel;
                if (!item.issel) {
                    ComFunJS.DelItem(model.SelRoles, "RoleCode", item.RoleCode)
                } else {
                    if (ComFunJS.FindItem(model.SelRoles, function (e) {
                      return e.RoleCode == item.RoleCode;
                    }).length == 0) {
                        model.SelRoles.push(item)
                    }
                }
            },
            SelRoleAll: function (dom) {
                if ($(dom).hasClass("fa-square-o")) {
                    model.QueryRoles.forEach(function (item) {
                        item.issel = true;
                        if (ComFunJS.FindItem(model.SelRoles, function (e) {
                   return e.RoleCode == item.RoleCode;
                        }).length == 0) {
                            model.SelRoles.push(item)
                        }
                    })
                    $(dom).removeClass("fa-square-o").addClass("fa-check-square-o")
                } else {
                    model.QueryRoles.forEach(function (item) {
                        item.issel = false;
                        ComFunJS.DelItem(model.SelRoles, "RoleCode", item.RoleCode)

                    })
                    $(dom).removeClass("fa-check-square-o").addClass("fa-square-o")
                }

            },
            SelRoles: [],//已选择用户
            DelSelRole: function (item) {
                ComFunJS.DelItem(model.SelRoles, "RoleCode", item.RoleCode);
                model.QueryRoles.forEach(function (el) {
                    if (el.RoleCode == item.RoleCode) {
                        el.issel = false;
                    }
                })
            }, 
            QueryRoles: [],//查询用户结果
            render: function () { 
            }
        })
        avalon.ready(function () {
            ComFunJS.initsetajax
            model.GetRoleList();
        })
        function getqiandaopeople() {
            var RoleName = "";
            var RoleCode = ""; 
            model.SelRoles.forEach(function (item) {
                RoleCode = RoleCode + item.RoleCode + ",";
                RoleName = RoleName + item.RoleName + ",";
            })
            RoleName = RoleName.substr(0, RoleName.length - 1);
            RoleCode = RoleCode.substr(0, RoleCode.length - 1); 
            var people = { 'RoleCode': RoleCode, 'RoleName': RoleName };
            return people;

        }
    </script>
</body>
</html>